package com.bootemp.control;

import com.bootemp.bean.Dept;
import com.bootemp.service.DeptService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping(value = "dept")
public class DeptControl {
    @Resource
    public DeptService ds;
    @PostMapping(value = "/insert")
    public int insert(Dept d){
        return ds.insert(d);
    }
    @GetMapping(value = "/all")
    public List<Dept> all(){
        return  ds.all();
    }
    @DeleteMapping(value = "/delete")
    public int delete(int id){
        return  ds.delete(id);
    }
    @GetMapping(value = "/one")
    public Dept one(int id){
        return  ds.one(id);
    }
    @PutMapping(value = "/update")
    public  int update(Dept d){
        return ds.update(d);
    }
    @GetMapping(value = "/page")
    public PageInfo<Dept> page(int cur){
        //设置当前页及长度
        PageHelper.startPage(cur,5);//第一个参数为当前页  第二个参数为长度
        //查询所有
        List<Dept> data=ds.all();
        return new PageInfo<>(data);
    }
}
